﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Pahan.McuFusion.Common.ComponentModel;

namespace Pahan.McuFusion.Common
{
    [TypeConverter(typeof(HardwareAdapterInfoConverter))]
    [Serializable]
    public abstract class HardwareAdapterInfo : BaseInfo
    {
        /// <summary>
        /// Checks whethes the specified hardware interface is supported by the adapter.
        /// </summary>
        public abstract bool Supports(HardwareInterfaceInfo hardwareInterface);

        /// <summary>
        /// Creates an instance of the adapter.
        /// </summary>
        public abstract IHardwareAdapter CreateAdapter(IHardwareInterface hardwareInterface);

        /// <summary>
        /// Checks whether the hardware adapter class implements the
        /// specified interface.
        /// </summary>
        public bool Implements<T>() where T : IHardwareAdapter
        {
            foreach (var type in ImplementedInterfaces)
            {
                if (typeof(T).IsAssignableFrom(type))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Gets the list of the interfaces implemented by the realization
        /// of the IHardwareAdapter.
        /// </summary>
        protected abstract IList<Type> ImplementedInterfaces
        {
            get;
        }
    }
}
